import api from "@/api/apiServer";
import { goodColumns } from "@/pages/ProductionPlan/components/tableConfig";
import { orderColumns } from "@/pages/Order/components/tableConfig";
import { filterDate } from "@/unit/tool";
let processingOption = [];
let pickingOption = [];
async function getProcessingOption(parentCode) {
  let res = await api.DictFindByCode({ parentCode });
  processingOption = res.data;
}
async function getPickingOption(parentCode) {
  let res = await api.DictFindByCode({ parentCode });
  pickingOption = res.data;
}
getProcessingOption("dict.processing", processingOption);
getPickingOption("dict.picking", pickingOption);

// 格式化数据来源
function caseSource(value, option) {
  let result = option.filter((item) => {
    return item.id === value;
  });

  if (result.length > 0) {
    return result[0].dictName;
  } else {
    return "";
  }
}
const columns = [
  {
    title: "序号",
    dataIndex: "index",
    key: "index",
    customRender: (text, record, index) => `${index + 1}`,
    align: "center",
  },
  {
    title: "入库单号",
    dataIndex: "acceptanceNum",
    key: "acceptanceNum",
    align: "center",
  },
  {
    title: "加工单号",
    dataIndex: "processNum",
    key: "processNum",
    align: "center",
  },
  // {
  //   title: "生产计划",
  //   dataIndex: "wareHouse",
  //   key: "wareHouse",
  //   align: "center",
  // },
  // {
  //   title: "加工单号",
  //   dataIndex: "processingOrderNum",
  //   key: "processingOrderNum",
  //   align: "center",
  // },
  {
    title: "商品编码",
    dataIndex: "goodsCode",
    key: "goodsCode",
    align: "center",
  },
  {
    title: "商品名称",
    dataIndex: "goodsName",
    key: "goodsName",
    align: "center",
  },
  {
    title: "商品规格",
    dataIndex: "specifications",
    key: "specifications",
    align: "center",
  },
  {
    title: "库位",
    dataIndex: "shelfNames",
    key: "shelfNames",
    align: "center",
    scopedSlots: { customRender: 'shelfNames' },
  },
  {
    title: "入库总数量",
    dataIndex: "wareNum",
    key: "wareNum",
    align: "center",
  },

  {
    title: "入库时间",
    dataIndex: "createtime",
    key: "createtime",
    align: "center",
    customRender: (text, record, index) => {
      return filterDate(text);
    },
  },
  {
    title: "入库人",
    dataIndex: "createdBy",
    key: "createdBy",
    align: "center",
  },
  {
    title: "操作",
    dataIndex: "action",
    key: "action",
    align: "center",
    width: 150,
    fixed: "right",
    scopedSlots: { customRender: "action" },
  },
];

const order = [
  {
    title: "序号",
    dataIndex: "index",
    key: "index",
    customRender: (text, record, index) => `${index + 1}`,
    align: "center",
  },
  {
    title: "加工单号",
    dataIndex: "processNum",
    key: "processNum",
    align: "center",
  },

  {
    title: "生产计划",
    dataIndex: "planNum",
    key: "planNum",
    align: "center",
  },
  {
    title: "加工单数量",
    dataIndex: "productionQuantity",
    key: "productionQuantity",
    align: "center",
  },
  // {
  //   title: "完工数量",
  //   dataIndex: "rescri",
  //   key: "rescri",
  //   align: "center",
  // },
  {
    title: "班次",
    dataIndex: "workTeamName",
    key: "workTeamName",
    align: "center",
  },

  {
    title: "备料",
    dataIndex: "pickStatus",
    key: "pickStatus",
    align: "center",
    customRender: (text, record, index) => {
      return caseSource(text, pickingOption);
    },
  },
  {
    title: "状态",
    dataIndex: "status",
    key: "status",
    align: "center",
    customRender: (text, record, index) => {
      return caseSource(text, processingOption);
    },
  },
  {
    title: "开始时间",
    dataIndex: "processStartTime",
    key: "processStartTime",
    align: "center",
    customRender: (text, record, index) => {
      return filterDate(text);
    },
  },
  {
    title: "结束时间",
    dataIndex: "processEndTime",
    key: "processEndTime",
    align: "center",
    customRender: (text, record, index) => {
      return filterDate(text);
    },
  },
  {
    title: "备注",
    dataIndex: "remark",
    key: "remark",
    align: "center",
  },
];

const wareColumns = [
  {
    title: "序号",
    dataIndex: "index",
    key: "index",
    customRender: (text, record, index) => `${index + 1}`,
    align: "center",
  },
  {
    title: "库位编号",
    dataIndex: "label",
    key: "label",
    align: "center",
  },
  {
    title: "仓库名称",
    dataIndex: "wareHouseName",
    key: "wareHouseName",
    align: "center",
  },
  {
    title: "货区编号",
    dataIndex: "stockAreaName",
    key: "stockAreaName",
    align: "center",
  },
  {
    title: "货架编号",
    dataIndex: "shelfAreaName",
    key: "shelfAreaName",
    align: "center",
  },
  {
    title: "行",
    dataIndex: "rowLine",
    key: "rowLine",
    align: "center",
  },
  {
    title: "列",
    dataIndex: "col",
    key: "col",
    align: "center",
  },
  // {
  //   title: "库位二维码",
  //   dataIndex: "index2",
  //   key: "index2",
  //   align: "center",
  // },
];

const shelfModel = {
  tableOption: [],
};

const orderModel = {
  tableOption: [],
  replaceFields: {},
  name: "goodsName",
  columns: orderColumns,
  tableKey: "WorksheetList",
  code: "processNum",
};

const goodModel = {
  replaceFields: {
    children: "goodsTypeList",
    title: "goodsTypeName",
    key: "id",
    value: "id",
  },
  treeKey: "CommodityTypeFindAll",
  tableKey: "CommodityList",
  searchKey: "goodsType",
  name: "goodsName",
  code: "goodsCode",
  filename: "CommodityModal",
  columns: goodColumns,
  tableOption: [],
};

export { columns, order, shelfModel, wareColumns, goodModel, orderModel };
